﻿using FDEE.Model;
using FDEEDrawingModels;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FDEEMain
{
    public partial class FDEEParamentForm : Form
    {
        FDEEReber fdeeReber;
        public InitTypePara para = new InitTypePara();
        List<ParaItem> items;
        private List<Control> _listParamCtrl = new List<Control>(); // 动态创建控件

        List<string> _ListSubDes = new List<string>() {
        "墩高7.00-10.00", "墩高10.01-15.00","墩高15.01-20.00","墩高20.01-25.00"};
        private double _scaleX = 1;
        private double _scaleY = 1;
        public FootingPara footingPara = new FootingPara();
        public PilePara pilePara = new PilePara();
        public PierPara pierPara = new PierPara();
        public BeamPara beamPara = new BeamPara();
        public FDEEParamentForm()
        {
            InitializeComponent();
            plFMHK.Visible = false; ;
            using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
            {
                float dpiX = graphics.DpiX;
                float dpiY = graphics.DpiY;

                _scaleX += (dpiX - 96) * 1.041666 / 100;
                _scaleY += (dpiY - 96) * 1.041666 / 100;
            }
            InitForm();
            para = new InitTypePara();
        }
        private void InitForm()
        {
            var values = Enum.GetValues(typeof(FDEE.Model.eSubType));
            int index = 0;
            foreach (var item in values)
            {
                cbHeight.Items.Add(item);
                ++index;
            }

            if(cbHeight.Items.Count > 2)
            {
                cbHeight.SelectedIndex = 1;
            }

            //foreach (var item in values)
            //{
            //    cbPHeight.Items.Add(item);
            //    ++index;
            //}

            //if (cbPHeight.Items.Count > 2)
            //{
            //    cbPHeight.SelectedIndex = 1;
            //}

            //foreach (var item in values)
            //{
            //    cbCHeight.Items.Add(item);
            //    ++index;
            //}

            //if (cbCHeight.Items.Count > 2)
            //{
            //    cbCHeight.SelectedIndex = 1;
            //}

            //foreach (var item in values)
            //{
            //    cbBHeight.Items.Add(item);
            //    ++index;
            //}

            //if (cbBHeight.Items.Count > 2)
            //{
            //    cbBHeight.SelectedIndex = 1;
            //}

            InitType();
        }
        private void btnConfim_Click(object sender, EventArgs e)
        {
            try
            {
                para.type = cbSubType.Text;                             // 构造物子类型（字符串）
                para.eHeightType = (FDEE.Model.eSubType)cbHeight.SelectedIndex; // 墩高分类
                para.nHeightType = cbHeight.SelectedIndex;

                footingPara = new FootingPara();
                footingPara.type = cbSubType.Text;
                footingPara.eSubType = ((CBItem)cbSubType.SelectedItem).tag;                // 构造物子类型（枚举值）
                footingPara.eHeightType = (FDEE.Model.eSubType)cbHeight.SelectedIndex; // 墩高分类
                para.type = "Footing4Cal1";
                para.eType = EStructure.E_FOOT;// 构造物子类型（字符串）
                para.eHeightType = (FDEE.Model.eSubType)cbHeight.SelectedIndex; // 墩高分类
                para.nHeightType = cbHeight.SelectedIndex;
                if (cbSubType.Text == "FMHK")
                {
                    if (string.IsNullOrWhiteSpace(Length.Text))
                    {
                        MessageBox.Show("请输入Length值", "提示");
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(ccpile.Text))
                    {
                        MessageBox.Show("请输入Length值", "提示");
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(numpile.Text))
                    {
                        MessageBox.Show("请输入Length值", "提示");
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(sidepile.Text))
                    {
                        MessageBox.Show("请输入Length值", "提示");
                        return;
                    }
                    footingPara.Length = int.Parse(Length.Text);
                    footingPara.ccpile = int.Parse(ccpile.Text);
                    footingPara.numpile = int.Parse(numpile.Text);
                    footingPara.sidepile = int.Parse(sidepile.Text);
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch
            {
                this.DialogResult = DialogResult.Cancel;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }


        private void InitType()
        {

            //cbPSubType.DisplayMember = "name";
            //var values = Enum.GetValues(typeof(FDEE.Model.EPileType));
            //foreach (var item in values)
            //{
            //    CBItem data = new CBItem();
            //    int tag = (int)item;
            //    data.name = item.ToString();
            //    data.tag = tag;
            //    cbPSubType.Items.Add(data);
            //}

            cbSubType.DisplayMember = "name";
            var values = Enum.GetValues(typeof(FDEE.Model.EFootingType));
            foreach (var item in values)
            {
                CBItem data = new CBItem();
                int tag = (int)item;
                data.name = item.ToString();
                data.tag = tag;
                cbSubType.Items.Add(data);
            }

            //cbCSubType.DisplayMember = "name";
            //values = Enum.GetValues(typeof(FDEE.Model.eColumnType));
            //foreach (var item in values)
            //{
            //    CBItem data = new CBItem();
            //    int tag = (int)item;
            //    data.name = item.ToString();
            //    data.tag = tag;
            //    cbCSubType.Items.Add(data);
            //}

            //cbBSubType.DisplayMember = "name";
            //values = Enum.GetValues(typeof(FDEE.Model.ECrossBeamType));
            //foreach (var item in values)
            //{
            //    CBItem data = new CBItem();
            //    int tag = (int)item;
            //    data.name = item.ToString();
            //    data.tag = tag;
            //    cbBSubType.Items.Add(data);
            //}
        }

        public void ComboxEventHandler(object sender, EventArgs e)
        {
            ComboBox combo = sender as ComboBox;
            string str = combo.Name;
        }

        private void cbHeight_SelectedIndexChanged(object sender, EventArgs e)
        {
            string TypeName = cbSubType.Text;
          
            //if(tab.SelectedIndex==1)
            //    TypeName = cbPSubType.Text;
            //else if (tab.SelectedIndex == 2)
            //    TypeName = cbCSubType.Text;
            //else if (tab.SelectedIndex == 3)
            //    TypeName = cbBSubType.Text;
            //else
                //TypeName = cbSubType.Text;
            FDEE.Model.eSubType type = (FDEE.Model.eSubType)cbHeight.SelectedIndex;
            if (!string.IsNullOrWhiteSpace(TypeName))
            {
                string des = Common.GetPierHeightDes(TypeName, type);
                //if (tab.SelectedIndex == 1)
                //{
                //    desPLabel.Text = des;
                //    desPLabel.Refresh();
                //}
                //else if (tab.SelectedIndex == 2)
                //{
                //    desCLabel.Text = des;
                //    desCLabel.Refresh();
                //}
                //else if (tab.SelectedIndex == 3)
                //{
                //    //desBLabel.Text = des;
                //    //desBLabel.Refresh();
                //}
                //else
                //{
                    desLabel.Text = des;
                    desLabel.Refresh();
                //}
            }
        }

        private void cbSubType_SelectedIndexChanged(object sender, EventArgs e)
        {
            string TypeName = cbSubType.Text;
            if (TypeName == "FMHK")
            {
                plFMHK.Visible = true;
            }
            else
            {
                plFMHK.Visible = false; ;
            }
            cbHeight_SelectedIndexChanged(null, null);
        }
    }
    public class FootingPara
    {
        public string type { get; set; }                        // 构造物类型（字符串）
        public int eSubType { get; set; }                       // 构造物子类型
        public FDEE.Model.eSubType eHeightType { get; set; }    // 构造物墩高分类  
        public int Length { get; set; }
        public int ccpile { get; set; }
        public int numpile { get; set; }
        public int sidepile { get; set; }
    }
   
    public class PierPara
    {
        public string type { get; set; }                        // 构造物类型（字符串）
        public int eSubType { get; set; }                       // 构造物子类型
        public FDEE.Model.eSubType eHeightType { get; set; }    // 构造物墩高分类  
        public double pierHeight { get; set; } //墩高
        public string pierName { get; set; } //墩高
        public string lzSpace { get; set; } //闪电筋间距
        public string lzAddSpace { get; set; } //闪电筋间距
    }

    public class BeamPara
    {
        public string type { get; set; }                        // 构造物类型（字符串）
        public int eSubType { get; set; }                       // 构造物子类型
        //public FDEE.Model.eSubType eHeightType { get; set; }    // 构造物墩高分类  
        public double width { get; set; } //盖梁宽度

        public string pierName { get; set; } //墩高
        //public double leftwidth { get; set; } //墩高
    }
}
